<template>
  <div class="p-d">
    <div class="p-d b-f">
      <SearchComp :searchForm="searchForm" :searchData="queryString" :searchAction="searchAction"></SearchComp>
    </div>
    <div class="p-d b-f m-t">
      <div class="btnStyle flex-between ">
        <ButtonComp :buttonData="buttonData" />
      </div>
      <TableCompEle class="m-t" ref="multipleTable" :tableData="tableData" :tableConfig="tableConfig" :tableAction="tableAction" :isSelect="true"
        :isIndex="true" :isShowPage="true" :queryParams="queryParams" @getPagination="getList" @handleSelectionChange="handleSelectionChange">
      </TableCompEle>
    </div>
    <ImportDialog ref="importRef" />
    <AddExpert ref="addExperts" @close="getList" />
  </div>
</template>

<script>
import ImportDialog from './common/ImportDialog.vue'
import AddExpert from './common/addExpert.vue'
export default {
  components: { AddExpert, ImportDialog },
  data() {
    return {
      multipleSelection: [],
      queryParams: {
        total: 0,
        currentPage: 1,
        pageSize: 10
      },
      buttonData: [
        {
          kind: 'button',
          label: '新增',
          plain: false,
          size: 'small',
          type: 'primary',
          click: () => {
            this.$refs.addExperts.show({
              title: '新建专家',
              data: {
                talentsType: '专家'
              }
            })
          }
        },
        {
          kind: 'button',
          label: '批量导入',
          plain: false,
          size: 'small',
          type: 'primary',
          click: () => {
            this.$refs.importRef.show()
          }
        },
        {
          kind: 'button',
          label: '批量删除',
          plain: false,
          size: 'small',
          type: 'danger',
          click: () => {
            if (this.multipleSelection.length == 0) {
              this.$message({
                type: 'warning',
                message: '请选择要删除的数据'
              })
              return
            }
            const ids = []
            this.multipleSelection.forEach(items => {
              ids.push(items.id)
            })
            this.deleteFun(ids)
          }
        }
      ],
      tableData: [],
      tableConfig: [
        {
          prop: 'talentsName',
          label: '专家姓名'
        },
        {
          prop: 'jobTitle',
          label: '技术职称'
        },
        {
          prop: 'careerDirection',
          label: '职业方向'
        },
        {
          prop: 'label',
          label: '标签'
        }
      ],
      tableAction: {
        align: () => 'center',
        width: () => String(180),
        operations: [
          {
            label: '专家信息',
            isLink: true,
            type: 'primary',
            method: row => {
              this.look(row)
            }
          },
          {
            label: '修改',
            isLink: true,
            type: 'primary',
            method: row => {
              this.$refs.addExperts.show({
                title: '修改专家',
                data: {
                  data: row,
                  talentsType: '专家'
                }
              })
            }
          },
          {
            label: '删除',
            isLink: true,
            type: 'danger',
            method: row => {
              this.deleteFun(row)
            }
          }
        ]
      },
      queryString: {
        talentsName: ''
      },
      searchForm: {
        changeMethod: () => {
          this.queryParams.currentPage = 1
          this.getList()
        },
        formData: [
          {
            type: 'Input',
            label: '需求名称',
            prop: 'name',
            clearable: true,
            icon: 'el-icon-search',
            placeholder: '请输入需求名称'
          },
          {
            type: 'Input',
            label: '领域名称',
            prop: 'domainName',
            clearable: true,
            icon: 'el-icon-search',
            placeholder: '请输入领域名称'
          }
        ]
      },
      searchAction: [
        {
          label: '查询',
          type: 'primary',
          handle: () => {
            this.queryParams.currentPage = 1
            this.$refs.multipleTable.clearSelection()
            this.getList()
          }
        },
        {
          label: '重置',
          type: 'primary',
          plain: true,
          handle: () => {
            this.queryString = {
              name: '',
              domainName: ''
            }
            this.queryParams.currentPage = 1
            this.getList()
          }
        }
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    addFun() {
      this.$refs.addExperts.show({
        title: '新建专家',
        data: {
          talentsType: '专家'
        }
      })
    },
    getList() {
      let res = {
        code: 200,
        message: '操作成功',
        data: {
          pageSize: 10,
          totalPage: 1,
          total: 17,
          list: [
            {
              talentsId: 9491,
              talentsName: '张得开',
              talentsType: '专家',
              talentsPhone: '15834343433',
              identityCard: null,
              talentsSex: '男',
              declareUnitId: null,
              declareUnitName: null,
              technosphere: null,
              jobTitle: '测试',
              careerDirection: '测试',
              talentsState: 0,
              bindState: 0,
              userId: null,
              label: '测试',
              deleteFlag: 'n',
              createTime: '2024-01-24 14:55:09',
              createBy: 'admin',
              modifyTime: '2024-01-24 14:55:09',
              modifyBy: null,
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '未绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9479,
              talentsName: '草头王',
              talentsType: '专家',
              talentsPhone: '13663882272',
              identityCard: null,
              talentsSex: '男',
              declareUnitId: null,
              declareUnitName: '',
              technosphere: null,
              jobTitle: '科长',
              careerDirection: '处长',
              talentsState: 0,
              bindState: 0,
              userId: null,
              label: '1',
              deleteFlag: 'n',
              createTime: '2024-01-23 14:27:33',
              createBy: 'admin',
              modifyTime: '2024-01-23 14:40:30',
              modifyBy: 'admin',
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '未绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9469,
              talentsName: '专家姓名1',
              talentsType: '专家',
              talentsPhone: '13115401331',
              identityCard: null,
              talentsSex: '女',
              declareUnitId: null,
              declareUnitName: '',
              technosphere: null,
              jobTitle: '技术职称1',
              careerDirection: '职业方向：1',
              talentsState: 0,
              bindState: 0,
              userId: null,
              label: '4444',
              deleteFlag: 'n',
              createTime: '2024-01-19 11:25:51',
              createBy: 'admin',
              modifyTime: '2024-01-19 15:24:33',
              modifyBy: 'admin',
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '未绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9466,
              talentsName: '专家姓名1',
              talentsType: '专家',
              talentsPhone: '13115401331',
              identityCard: null,
              talentsSex: '男',
              declareUnitId: null,
              declareUnitName: '',
              technosphere: null,
              jobTitle: '技术职称：',
              careerDirection: '职业方向1',
              talentsState: 0,
              bindState: 0,
              userId: null,
              label: '',
              deleteFlag: 'n',
              createTime: '2024-01-19 10:36:17',
              createBy: 'admin',
              modifyTime: '2024-01-19 11:01:55',
              modifyBy: 'admin',
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '未绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9436,
              talentsName: '李一鸣q1',
              talentsType: '专家',
              talentsPhone: '17726538765',
              identityCard: null,
              talentsSex: null,
              declareUnitId: 35,
              declareUnitName: '111',
              technosphere: null,
              jobTitle: '教授',
              careerDirection: '航空雷达；航空通信设备',
              talentsState: 0,
              bindState: 0,
              userId: null,
              label: '航空航天;电子信息技术',
              deleteFlag: 'n',
              createTime: '2023-06-14 10:16:11',
              createBy: 'admin',
              modifyTime: '2024-01-19 09:41:58',
              modifyBy: 'admin',
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '未绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9459,
              talentsName: '专家',
              talentsType: '专家',
              talentsPhone: '1111',
              identityCard: null,
              talentsSex: null,
              declareUnitId: null,
              declareUnitName: '1111',
              technosphere: null,
              jobTitle: null,
              careerDirection: null,
              talentsState: 0,
              bindState: 0,
              userId: null,
              label: '',
              deleteFlag: 'n',
              createTime: '2024-01-12 16:54:29',
              createBy: 'admin',
              modifyTime: '2024-01-12 16:54:29',
              modifyBy: null,
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '未绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9438,
              talentsName: '刘裕达',
              talentsType: '专家',
              talentsPhone: '15372837465',
              identityCard: null,
              talentsSex: null,
              declareUnitId: 32,
              declareUnitName: '中科浩晖',
              technosphere: null,
              jobTitle: '教授',
              careerDirection: '医疗电子',
              talentsState: 0,
              bindState: 1,
              userId: 1282,
              label: '集成电路制造',
              deleteFlag: 'n',
              createTime: '2023-06-14 10:16:11',
              createBy: 'admin',
              modifyTime: '2023-07-12 15:32:39',
              modifyBy: 'admin',
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '已绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9437,
              talentsName: '张子谦',
              talentsType: '专家',
              talentsPhone: '13672839655',
              identityCard: null,
              talentsSex: null,
              declareUnitId: 1,
              declareUnitName: '中科浩晖',
              technosphere: null,
              jobTitle: '副教授',
              careerDirection: '军事电子；电子整机设计制造',
              talentsState: 0,
              bindState: 1,
              userId: 1281,
              label: '电子整机设计制造;通信电子;军事电子',
              deleteFlag: 'n',
              createTime: '2023-06-14 10:16:11',
              createBy: 'admin',
              modifyTime: '2023-07-12 15:31:05',
              modifyBy: 'admin',
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '已绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9450,
              talentsName: '刘成城',
              talentsType: '专家',
              talentsPhone: '13672893048',
              identityCard: null,
              talentsSex: null,
              declareUnitId: null,
              declareUnitName: '中科浩晖',
              technosphere: null,
              jobTitle: '教授',
              careerDirection: '光通信；光存储',
              talentsState: 0,
              bindState: 0,
              userId: null,
              label: '',
              deleteFlag: 'n',
              createTime: '2023-06-14 10:58:16',
              createBy: 'admin',
              modifyTime: '2023-06-14 11:11:12',
              modifyBy: 'admin',
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '未绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            },
            {
              talentsId: 9449,
              talentsName: '李建军',
              talentsType: '专家',
              talentsPhone: '18872639874',
              identityCard: null,
              talentsSex: null,
              declareUnitId: null,
              declareUnitName: '中科浩晖',
              technosphere: null,
              jobTitle: '副教授',
              careerDirection: '军事电子',
              talentsState: 0,
              bindState: 0,
              userId: null,
              label: '',
              deleteFlag: 'n',
              createTime: '2023-06-14 10:58:16',
              createBy: 'admin',
              modifyTime: '2023-06-14 11:10:49',
              modifyBy: 'admin',
              deptName: null,
              declareUnitIdArray: null,
              labelIds: null,
              labels: null,
              labelStr: null,
              talentsStateCn: '未入库',
              bindStateCn: '未绑定',
              relProjectUserVOList: null,
              userPortrait: null,
              bindUserName: null,
              talentExperience: null
            }
          ],
          page: 1
        }
      }
      this.tableData = res.data.list
      this.queryParams.total = res.data.total
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    deleteFun(ids) {
      if (ids.length == 0) {
        this.$message.warning('请选中要删除的数据')
        return
      }
      this.$confirm(`确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          console.log('[ ids ] >', ids)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    look(row) {
      this.$router.push({
        name: 'TalentDetail',
        query: {
          talentsId: row.talentsId
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>